package com.weipai.education.controller;

import com.weipai.education.model.Exchange;
import com.weipai.education.model.api.Response;
import com.weipai.education.service.ExchangeService;
import com.weipai.education.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/17 17:28
 * 
 * 退换货控制类
 */
@RestController
@Validated
public class ExchangeController {
    
    @Autowired
    private ExchangeService exchangeService;
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 退换货订单保存
     * @param exchange
     * @return
     */
    @RequestMapping(value = "/exchange/save", method = RequestMethod.POST)
    public Response save(@Valid Exchange exchange, String goodsBarCode,Integer orderId,Integer isHeadset){
        return exchangeService.save(exchange, goodsBarCode,orderId,isHeadset);
    }

    /**
     * 退换货订单分页查询
     * @param page
     * @param size
     * @param orderNumber
     * @param orderType
     * @param startTime
     * @param endTime
     * @param type:为null表示查询所有的，为own表示查询自己的
     * @return
     */
    @RequestMapping(value = "/exchange/list", method = RequestMethod.GET)
    public Response list(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                         @NotNull(message = "size不能为空") @RequestParam(value = "size") Integer size,
                                    @RequestParam(value = "orderNumber", required = false) String orderNumber,
                                    @RequestParam(value = "orderType", required = false) String orderType,
                                    @RequestParam(value = "startTime", required = false) String startTime,
                                    @RequestParam(value = "endTime", required = false) String endTime,
                                    @RequestParam(value = "type", required = false) String type){
        return exchangeService.list(page, size, orderNumber, orderType, startTime, endTime, type);
    }
    /**
     * 根据输入的订单号搜索一下子订单存不存在
     * @param key 输入的订单号
     * @return
     */

    @RequestMapping(value = "/searchOrderByOrderNumber",method = RequestMethod.GET)
    public Response searchOrderByOrderNumber (@NotNull(message = "订单号不能为空") String OrderNumber,String type,Integer userId){
        return purchaseService.searchOrderByOrderNumber(OrderNumber,type,userId);
    }
    /**
     * 审核退换货订单
     * @param status
     * @param id
     * @return
     */
    @RequestMapping(value = "/exchange/isAudit", method = RequestMethod.GET)
    public Response isAudit(@NotBlank(message = "状态不能为空") String status,
                            @NotBlank(message = "订单id不能为空") String id){
        return exchangeService.isAudit(status, id);
    }

    /**
     * 退换货详情
     * @param id
     * @return
     */
    @RequestMapping(value = "/exchange/exchangeInfo", method = RequestMethod.GET)
    public Response exchangeInfo(@NotBlank(message = "订单id不能为空") @RequestParam(value = "id") String id){
        return exchangeService.exchangeInfo(id);
    }
    
}
